<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class AdminEstate extends Authenticatable implements JWTSubject
{
    use Notifiable;

    protected $table   = 'admin_estate';
    protected $guarded = [];

    protected $fillable = [
        'id', 'username', 'nickname', 'estate_id', 'pid','password'
    ];

    public function roles()
    {
        return $this->belongsToMany(EstateRole::class, 'admin_estate_role', 'admin_id', 'role_id');
    }

    /**
     * Notes: 关联物业
     * User: lstink
     * Date: 2021/1/29
     * Time: 3:42 下午
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function estate()
    {
        return $this->hasOne(Property::class, 'id', 'estate_id');
    }

    /**
     * Notes: 关联用户菜单
     * User: lstink
     * Date: 2021/1/28
     * Time: 3:43 下午
     */
    public function menus()
    {
        return $this->belongsToMany(EstateRoleMenu::class, AdminEstateRole::class, 'admin_id', 'role_id', 'id', 'role_id')->where('estate_role_menus.estate_id', $this->estate_id);
    }

    //    public function menus()
//    {
//        return $this->hasManyThrough(EstateRoleMenu::class, AdminEstateRole::class, 'admin_id', 'role_id', 'id', 'role_id')->where();
//    }


    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    public function getJWTCustomClaims()
    {
        return [];
    }
}
